/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.gerenciamento.pg.framework.jpa.eclipselink.repository;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.eclipse.persistence.jpa.JpaHelper;
import org.eclipse.persistence.queries.ReadAllQuery;
import org.springframework.data.domain.Persistable;

/**
 *
 * @author wolmirgarbin
 */
public class FindByExampleRepository<T extends Persistable>{
    
    @PersistenceContext
    private EntityManager em;
    
    public List<T> findByExample(final T example){
        ReadAllQuery readQuery = new ReadAllQuery(example, new QueryByExamplePolicy());
        return JpaHelper.createQuery(readQuery, em).getResultList();
    }
}
